package com.edu.controller;

import com.edu.entity.Subject;
import com.edu.entity.SubjectScore;
import com.edu.service.SubjectService;
import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SubjectController
 * @Description 学科
 * @Author W.Jian
 * @Date 2021/5/22 12:57
 **/
@RestController
@RequestMapping("subject")
public class SubjectController {

    @Autowired
    SubjectService subjectService;

    /**
     * 添加课程
     * @return
     */
    @PostMapping("insertSubject")
    public Result insertSubject(@RequestBody Subject subject){
        boolean save = subjectService.save(subject);
        if(save){
            return Result.success();
        }
        return Result.failure();
    }

    /**
     * 查询所有课程
     * @return
     */
    @GetMapping("listAll")
    public Result listAll(){
        List<Subject> list = subjectService.list();
        return Result.success(list,list.size());
    }

    /**
     * 查询所有课程  条件查询
     * @return
     */
    @PostMapping("list")
    public Result list(@RequestBody Subject subject){
        List<Subject> list = subjectService.listByCondition(subject);
        return Result.success(list,list.size());
    }
    /**
     * 专业添加课程
     * @return
     */
    @PostMapping("insertRef")
    public Result insertRef(@RequestBody SubjectScore subjectScore){
        return subjectService.insertRef(subjectScore);
    }
    /**
     * 根据专业查询课程
     * @return
     */
    @PostMapping("listByMajor")
    public Result listSubjectRef(Long schoolId,Long majorId){
        return subjectService.listSubjectRef(schoolId,majorId);
    }

    /**
     * 删除
     * @return
     */
    @PostMapping("updateDelFlag")
    public Result updateDelFlag(Long subjectId){
        return subjectService.updateDelFlag(subjectId);
    }


}
